// The form contains fields for many pagiantion optiosn so you can 
// quickly see the resuluts of the different options.
// This function creates an option object for the pagination function.
// This will be be unnecessary in your application where you just set
// the options once.
$(function() {
		var items_on_page = 20;
		var pages_step = 5;
		
		get_data(1, 20);
		$.ajax({
			type: "POST",
			url: "/topic/topic_total",
			data: {
			type: "get"},
			success: function(total)
			{
				$("#paging").jpaging({
					all_items_num: total,
					callback: get_data,
					items_on_page: items_on_page,
					pages_step: pages_step
				});
			}
		});

		function get_data(start_index, end_index){
			start_index = start_index - 1;
			end_index = end_index - 1;
			$.ajax({
				type: "POST",
				url: "/topic/topic_paging",            
				data: {start_index: start_index,
				end_index: end_index,
				type: "get"},
				success: function(html)
				{                  
					$("#demo_tbl").html(html);
					$.prettyDate.now = function() {
						return new Date();
					}
					$("a").prettyDate();

				}
			});			
		}

		$("#post_comment_button").click(function(){
		var comment = $("#topic_comment_text").val();
                if(comment.length > 0) {
                        $("#topic_comment_text").attr("value", '');
                        comment = comment.replace('\n', '<br />');
                        $.ajax({
                                type: "POST",
                                url: "/topic/comment",
                                data: {
                                comm_id: $("#comm_id").val(),
                                topic_id: $("#topicid").val(),
                                comment: comment,
                                type: "get"},
                                success: function(html)
                                {
					$("#comment_div").html(html);
					$.prettyDate.now = function() {
						return new Date();
					}
					$("a").prettyDate();
					
                                }
                        });
                }
        });


});
